 using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class View_Admin_QuanLyKhachHang : System.Web.UI.Page
{
    QLKhachHang kh = new QLKhachHang();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            GridView1.DataSource = kh.Load_KH();
            GridView1.DataBind();
        }
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string tendn = (string)GridView1.Rows[e.RowIndex].Cells[0].Text.ToString();
        GridView1.DataSource = kh.Delete_KH(tendn);
        GridView1.DataSource = kh.Load_KH();
        GridView1.DataBind();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        GridView1.DataSource = kh.Load_KH();
        GridView1.DataBind();
        DropDownList chucnang = (DropDownList)GridView1.Rows[e.NewEditIndex].Cells[4].FindControl("DropDownList1");
        chucnang.DataSource = kh.Load_ChucNang();
        chucnang.DataValueField = "macn";
        chucnang.DataTextField = "tenchucnang";
        chucnang.DataBind();
        chucnang.Items.FindByValue(GridView1.DataKeys[e.NewEditIndex].Value.ToString()).Selected = true;
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        GridView1.DataSource = kh.Load_KH();
        GridView1.DataBind();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string tendn="";
        string tendn = GridView1.Rows[e.RowIndex].Cells[0].Text;
        DropDownList chucnang = (DropDownList)GridView1.Rows[e.RowIndex].Cells[4].FindControl("DropDownList1");
        GridView1.DataSource = kh.Update_KH(tendn, chucnang.SelectedValue);
        GridView1.EditIndex = -1;
        GridView1.DataSource = kh.Load_KH();
        GridView1.DataBind();
    }
}
